const drag = (app: any) => app.directive('drag', {
  mounted(el: HTMLElement) {
    el.addEventListener('mousedown', (e: MouseEvent) => {
      el.style.cursor = 'pointer'

      let x = e.pageX - el.offsetLeft
      let y = e.pageY - el.offsetTop

      const move = (e: MouseEvent) => {
        el.style.left = e.pageX - x + 'px'
        el.style.top = e.pageY - y + 'px'
      }

      window.addEventListener('mousemove', move)

      window.addEventListener('mouseup', () => {
        el.style.cursor = ''
        window.removeEventListener('mousemove', move)
      })
    })
  }
})

export default drag; 